package com.joinpay.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.joinpay.service.ProjectService;

@Controller
public class ProjectController {

	@Resource
	private ProjectService projectService;
	
	/**
	 * 插入新项目
	 */
	@RequestMapping(produces = "text/plain;charset=UTF-8", value = "addProject", method = RequestMethod.POST)
	@ResponseBody
	public String addProject(HttpServletRequest request) {
		Map<String, Object> mapSend = new HashMap<String, Object>();
		try {
			mapSend.put("repertory", request.getParameter("repertory"));
			mapSend.put("svnPath", request.getParameter("svnPath"));
			mapSend.put("type", request.getParameter("type"));
			mapSend.put("describe", request.getParameter("describe"));
			int sign = projectService.addProject(mapSend);
			mapSend.put("flag", "success");
			if (sign == 0) {
				mapSend.put("flag", "fail");
			}
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			mapSend.put("flag", "fail");
		}
		return JSON.toJSONString(mapSend);
	}
}
